home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / simul.eq < prev    next >
Text File  |  1995-03-23  |  8KB  |  249 lines

  1. Article 5278 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!sdd.hp.com!hp-pcd!hpcvra.cv.hp.com!rnews!hpcvbbs!akcs.wiser1
  3. From: akcs.wiser1@hpcvbbs.UUCP (steven lee wiser)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: simul.non-linear equations
  6. Keywords: hp-48sx,non-linear,equations,multiple
  7. Message-ID: <27eb7ecf:2507comp.sys.handhelds@hpcvbbs.UUCP>
  8. Date: 23 Mar 91 16:40:07 GMT
  9. Lines: 235
  10.  
  11.  
  12. Simultaneous Non-Linear Equation Solver:  Nonlinear and linear 
  13.  
  14.     This is a program description that solves simultaneous non-linear 
  15. equations, similar to the programs like TK-Solver Plus ( sold by 
  16. Universal Technical Systems, 1220 Rock St. Rockford. Il. 1-800-435-
  17. 7887).  Of course this is not as powerful as TK, but I think you will be 
  18. impressed by what the HP-48Sx can do.  I have solved up to 10 non-linear 
  19. equations will  this routine.  Patience is necessary with your HP-48sx 
  20. above 10 equations or if the equations are of complicated form. 
  21.  
  22.     This routine uses the solution developed in the book "Design of 
  23. Thermal Systems", third edition, by W. R. Stoecker , published by McGraw 
  24. Hill.   The Newton-Raphson Method with multiple equations  and unknowns 
  25. is the mathematical method used.             
  26.  
  27.     Approximately 1k of memory is used by the basic routines.  
  28. Additional memory is used for the equations and guess terms. 
  29.  
  30.     Additionally, linear equations can be easily solved with this 
  31. system.  Usually only one iteration is necessary for the linear system.  
  32. With this system, the equations can be written in any form or order as 
  33. is convenient. 
  34.  
  35. SIMUL.EQ    Name of the directory on my HP-28S or 48SX
  36.  
  37.             The following are words in the SIMUL.EQ directory:
  38.  
  39. CONT        control program for solving the equations
  40.  
  41. u           test for convergence number
  42.  
  43. NEW.G       sequence that defines the new guesses of values
  44.  
  45. DIF.F       program sequence that takes the partial derivatives
  46.  
  47. EVA.F       program sequence to evaluate the primary functions at each 
  48.             iteration guess value. 
  49.  
  50. F           list of equation names      ex. { f1 f2 f3 ...}
  51.  
  52. L           list of variable names      ex. { x y z ....}
  53.  
  54. CONT        << 0 'ITER' STO F 
  55.                SIZE 'A' STO {A 1 } 
  56.                1 CON { A 1 } 0 CON 
  57.                TMP1' STO 'TMP2' 
  58.                STO
  59.                   DO NEW.G 'ITER' 1
  60.                STO+ 
  61.                   UNTIL TMP1 TMP2  - 
  62.                ARRY->  DROP  A  1  -  1  
  63.                       START +  -1 
  64.                       STEP ABS u <
  65.                   END 440 .5 BEEP 
  66.              >>
  67.  
  68. u           .1    This value should vary based upon the magnitude of     
  69.      
  70. the guess values.   Ex. variable guess  values of 1000 should indicate 
  71. that a relative large value for u should be used; for small variable 
  72. guess values a small value of u should be used.  If a large guess and a 
  73. small guess are both in the problem experience should dictate which is 
  74. the most important value to govern the control value. 
  75.  
  76. NEW.G       << 1  A 
  77.                   FOR J 'L(J)' EVAL
  78.                EVAL
  79.                   NEXT { A 1 }  ->ARRY
  80.                'TMP1' STO 1 A 
  81.   HHHH$$$$JR(J)' EVAL
  82.                EVAL  
  83.                   NEXT { A 1 }  ->ARRY
  84.                DIF.F  -  ARRY->  DROP A 1
  85.                   FOR K 'L(K)' EVAL
  86.                STO   -1 
  87.                   STEP 1 A
  88.                   FOR J 'L(J)' EVAL
  89.                EVAL
  90.                   NEXT { A 1 }  ->ARRY
  91.                'TMP2' STO
  92.              >>
  93.  
  94.                             
  95.  
  96. DIF.F       <<  EVA.F  1  A
  97.                    FOR J 1 A 
  98.                       FOR K 'F(J)'        
  99.                 EVAL  'L(K)' EVAL  d    (see d  explained below)
  100.                       NEXT
  101.                    NEXT { A A  }  ->ARRY
  102.                 /
  103.              >>
  104.  
  105.                     WHERE ' d  ' is the differential symbol in HP-28s
  106.                                  and now the HP-48SX.
  107.  
  108.  
  109. EVA.F        << 1 A
  110.                    FOR J 'F(J)' EVAL
  111.                 EVAL EVAL 
  112.                    NEXT { A 1 }  ->ARRY
  113.               >>
  114.  
  115.                 
  116.     Note: for very complicated equations it may be necessary to 
  117. experiment with additional numbers of "EVAL" where you see 2 or 3 of 
  118. them presently. 
  119.  
  120.     Example of a equation:     f1
  121.  
  122.             z = x^2 + y*SIN(x)  with   variables x , y , z 
  123.  
  124.                 rewrite f1 to be :     x^2 + y*sin(x) - z 
  125.  
  126.            
  127.     This routine sets up the equations like this:
  128.  
  129.               ---------------MATRIX----------------------- /   EVAL-----
  130.       f1  :   d(f1)/d(x)   d(f1)/d(y)   d(f1)/d(z)  ....   /  
  131. f1(x,y,z,..)    
  132.       f2  :   d(f2)/d(x)   d(f2)/d(y)   d(f2)/d(z)  ....   /  
  133. f2(x,y,z...) 
  134.       f3  :   d(f3)/d(x)   d(f3)/d(y)   d(f3)/d(z)  ....   /  
  135. f3(x,y,z...) 
  136.        |          |            |            |              |   |
  137.        |          |            |            |              |   |
  138.            
  139.  
  140.          f1 f2 f3 are initially evaluated at the initial guess values
  141.  
  142.          x , y and z.... are solved based on matrix algebra 
  143.  
  144.          These new values of x, y, and z are then used to evaluate the   
  145.  
  146. equations f1, f2, f3 again to achieve a new set of x, y, and z guess 
  147. values. This continues until the sum of the differences from one f1 to 
  148. another f1 thru f3... is less than the test value given in the term "u." 
  149.  
  150.     To review to final answers look at either one of the "temp" matrices 
  151. oreview the actual variables within the list.
  152.  
  153.     Whenever the test value is less than the sum of the differences the 
  154. routine stops and beeps.  This routine can be changed in various ways.  
  155. One is to beep at each iteration.  Another is to send to the screen the 
  156. values of the variables to indicate how the solution is progressing. 
  157.  
  158. Have a good time with it.  Steve Wiser 
  159.                             Richmond Va
  160.  
  161.  I assume no responsiblity for any use of this program whatsoever. Slw 
  162.  
  163. Uploadable program 
  164. follows:
  165.  
  166. %%HP: T(3)A(D)F(.);
  167. DIR
  168.   F { F1 F2 F3 }
  169.   L { X Y Z }
  170.   \Gm LLLL  CONTROL
  171.     \<TIME 0 'ITER'
  172. STO F SIZE 'A' STO
  173. { A 1 } 1 CON { A 1
  174. } 0 CON 'TMP1' STO
  175. 'TMP2' STO
  176.       DO XXX 'ITER'
  177. 1 STO+
  178.       UNTIL TMP1
  179. TMP2 - OBJ\-> DROP A
  180. 1 - 1
  181.         START + -1
  182.         STEP ABS \Gm
  183. \<=
  184.       END 440 .5
  185. BEEP TIME SWAP -
  186. 10000 *
  187.     \>>
  188.   XXX
  189.     \<< 1 A
  190.       FOR j 'L(j)'
  191. EVAL EVAL
  192.       NEXT { A 1 }
  193. \->ARRY 'TMP1' STO 1
  194. A
  195.       FOR j 'L(j)'
  196. EVAL EVAL
  197.       NEXT { A 1 }
  198. \->ARRY ZZZ - OBJ\->
  199. DROP A 1
  200.       FOR k 'L(k)'
  201. EVAL STO -1
  202.       STEP 1 A
  203.       FOR j 'L(j)'
  204. EVAL EVAL
  205.       NEXT { A 1 }
  206. \->ARRY 'TMP2' STO
  207.     \>>
  208.   ZZZ
  209.     \<< YYY 1 A
  210.       FOR j 1 A
  211.         FOR k 'F(j)
  212. ' EVAL 'L(k)' EVAL
  213. \.d
  214.         NEXT
  215.       NEXT { A A }
  216. \->ARRY /
  217.     \>>
  218.   YYY
  219.     \<< 1 A
  220.       FOR j 'F(j)'
  221. EVAL EVAL EVAL
  222.       NEXT { A 1 }
  223. \->ARRY
  224.     \>>
  225. END
  226.  
  227. An example of a set of equations if as follows:
  228.  
  229. let F1 be  .... DP-5*w^2-500             from DP = 5*w + 500
  230. let F2 be  .... 1000-30*w1-4.75*w1^2-DP  from DP = 1000-30 * w1 - 4.75 * 
  231.                                                   w1^2
  232. let F3 be  .... 900-45*w2-30*w2^2-DP     from DP = 900 - 45 * w2 - 30 * 
  233.                                                   w2^2
  234. let f4 be ..... w-w1-w2                  from w = w1 + wlways 
  235. return a solution to just any set of equations.
  236.  
  237. Note: This was originally written when I had my HP-28c believe it or 
  238. not. And with it I was able to solve up to six or seven simple 
  239. equations.
  240.  
  241. Note that the downloadable program has a change that lets you see how
  242. much time it takes to solve an equation set. Other changes can easily be
  243. made. One that has recently come to mind is not using the stack as I do
  244. now and using simply an matrix instead.
  245.  
  246. slw finally figure out how to upload.  Use GeoWorks Ensemble...
  247.  
  248.  
  249.